
<?php
	echo $this->element('menu');
?>

<div id="list-user">
	<div class="container">
		<div class="panel-group" id="accordion">
		<?php
			$i=0;
			foreach($userSendMessages as $user){

		?>
		
		  <div class="panel panel-default">
		    <div class="panel-heading">
		      <h4 class="panel-title">
		        <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $i;?>">
		          <?php 
		          	echo $user['Profile']['name']; 
		          	if($user['newMessage'] > 0){
		          ?>
		          <span class="badge"><?php echo $user['newMessage']; ?> new message</span>
		          <?php } ?>
		        </a>
		      </h4>
		    </div>
		    <div id="collapse<?php echo $i;?>" class="panel-collapse collapse">
		      <div class="panel-body">
		        <?php
		        	foreach($user['Message'] as $message){
		        		if($message['UserMessage']['from_user_id'] == $user['User']['id']){
		        ?>
		        			<p style="color:blue; text-align:left"><?php echo $message['UserMessage']['message']; ?>
		        			</p>
		        			<hr>
				<?php
		        		}else{
		        ?>
		        			<p style="color:black; text-align:right"><?php echo $message['UserMessage']['message']; ?>
		        			</p>
		        			<hr>
		        <?php
		        		}
		        	}
		        	
		        ?>
				<a href="/pinterest/UserMessages/viewNewMessage/<?php echo $user['User']['id'];?>">
					<button type="button" class="btn btn-default" style="width:100%;">Reply</button>
				</a>
		      </div>
		    </div>
		  </div>

		<?php
				$i++;
			}
		?>

		<?php
			foreach($userAthor as $user){

		?>
		
		  <div class="panel panel-default">
		    <div class="panel-heading">
		      <h4 class="panel-title">
		        <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $i;?>">
		          <?php 
		          	echo $user['Profile']['name']; 
		          //	if()	
		          ?>
		        </a>
		      </h4>
		    </div>
		    <div id="collapse<?php echo $i;?>" class="panel-collapse collapse">
		      <div class="panel-body">
		      	
		        <?php
		        	
		        ?>
				<a href="/pinterest/UserMessages/viewNewMessage/<?php echo $user['User']['id'];?>">
					<button type="button" class="btn btn-default" style="width:100%;">Send message</button>
				</a>
		      </div>
		    </div>
		  </div>

		<?php
				$i++;
			}
		?>
		</div>
	</div>
</div>
